﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography;
using System.Web;
using System.Web.Mvc;
using System.Web.UI.WebControls;
using SmallShop.BaseWeb;
using SmallShop.Bll;
using SmallShop.Frame;
using SmalShop.Model;

namespace SmallShop.ManagerWeb.Controllers
{
    public class BannerController : SmallController
    {
        private BannerBiz _biz;

        public BannerController()
        {
            _biz = new BannerBiz();
        }

        public ActionResult Index()
        {
            return View();
        }

        public ActionResult List(int page = 1, int limit = 10)
        {
            var query = _biz.Query();
            var count = query.Count();
            var rows = query.OrderBy(it => it.Sequence).Skip((page - 1)*limit).Take(limit).ToArray();
            return Json(new ResultModel
            {
                Data = new {count, rows}
            });
        }

        [HttpPost]
        public ActionResult Add( BannerModel m)
        {
            return Json(_biz.Add(m));
        }

        [HttpPost]
        public ActionResult Update(BannerModel m)
        {
            return Json(_biz.Update(m));
        }

        [HttpPost]
        public ActionResult Delete(long id)
        {
            return Json( _biz.Delete(id));
        }

    }
}